package lang

import (
	"fmt"
	"reflect"
)

func mainArray() {
	arr := [...]int{1, 2, 3}
	fmt.Println(arr)
	fmt.Println(reflect.TypeOf(arr).Kind())

	slice := []int{1, 2, 3}
	fmt.Println(slice)
	fmt.Println(reflect.TypeOf(slice).Kind())

	var s []int
	printSlice(s)

	// append works on nil slices.
	s = append(s, 0)
	printSlice(s)

	// The slice grows as needed.
	s = append(s, 1)
	printSlice(s)

	// We can add more than one element at a time.
	s = append(s, 2, 3, 4)
	printSlice(s)

	slice1 := []int{5, 23, 10, 2, 61, 33}
	// 对slices1进行切片，长度为2容量为3
	slice2 := slice1[2:6]
	fmt.Println("cap", cap(slice2))
	fmt.Println("slice2", slice2)
}

func printSlice(s []int) {
	fmt.Printf("len=%d cap=%d %v\n", len(s), cap(s), s)
}
